<template>
    <div>
        <city-header></city-header>
        <city-search :cities="cities" :alphabet="alphabet"></city-search>
        <city-list :hotCitiesList="hotCities" :cities="cities" :letter="letter"></city-list>
        <city-alphabet :alphabet="alphabet" @change="changeLetter"></city-alphabet>
    </div>
</template>
<script>
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
import axios from 'axios'
export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data () {
    return {
      hotCities: [],
      cities: {},
      letter: ''
    }
  },
  computed: {
    alphabet () {
      return Object.keys(this.cities)
    }
  },
  methods: {
    changeLetter (letter) {
      this.letter = letter
    }
  },
  mounted () {
    axios.get('/api/city.json').then((res) => {
      let result = res.data
      if (result.ret && result.data) {
        result = result.data
        // console.log(result)
        this.city = result.city
        this.hotCities = result.hotCities
        this.cities = result.cities
        // console.log(Object.keys(this.cities))
      }
    })
  }
}
</script>
